var element = layui.element;
var form = layui.form;
var $ = layui.jquery;
var layedit = layui.layedit;
var colorpicker = layui.colorpicker;
var table = layui.table;


var data_th = [[
  { type: 'checkbox' },
  { field: 'spmc', width: 300, title: '商品名称', templet: '#spTemplet' },
  { field: 'pp', width: 130, title: '品牌' },
  { field: 'jg', width: 130, title: '价格(元)' }
]];
var data_tb = [
  {
    "spmc": {
      "img": "../assets/images/48x48.jpg",
      "title": "Nike耐克男鞋科比毒液6科比毒液还素质",
      "stitle": "102923"
    },
    "pp": "雅诗兰黛",
    "jg": "<b>￥120.00</b>",
  },
  {
    "spmc": {
      "img": "../assets/images/48x48.jpg",
      "title": "Nike耐克男鞋科比毒液6科比毒液还素质",
      "stitle": "102923"
    },
    "pp": "雅诗兰黛",
    "jg": "<b>￥120.00</b>",
  }, {
    "spmc": {
      "img": "../assets/images/48x48.jpg",
      "title": "Nike耐克男鞋科比毒液6科比毒液还素质",
      "stitle": "102923"
    },
    "pp": "雅诗兰黛",
    "jg": "<b>￥120.00</b>",
  }, {
    "spmc": {
      "img": "../assets/images/48x48.jpg",
      "title": "Nike耐克男鞋科比毒液6科比毒液还素质",
      "stitle": "102923"
    },
    "pp": "雅诗兰黛",
    "jg": "<b>￥120.00</b>",
  }, {
    "spmc": {
      "img": "../assets/images/48x48.jpg",
      "title": "Nike耐克男鞋科比毒液6科比毒液还素质",
      "stitle": "102923"
    },
    "pp": "雅诗兰黛",
    "jg": "<b>￥120.00</b>",
  }, {
    "spmc": {
      "img": "../assets/images/48x48.jpg",
      "title": "Nike耐克男鞋科比毒液6科比毒液还素质",
      "stitle": "102923"
    },
    "pp": "雅诗兰黛",
    "jg": "<b>￥120.00</b>",
  }

];


table.render({
  elem: '#test',
  cellMinWidth: 80,
  height: 361,
  cols: data_th,
  data: data_tb
});

function selectShop() {
  layer.open({
    skin: 'zp-popup',
    id: 'selpro',
    title: '选择商品',
    content: $("#selproPopup"),
    area: "640px",
    type: 1,
    cancel: function () {
      setTimeout(function () {
        $("#selproPopup").hide();
      }, 10);
    }
  });
}
function selectShopBtn(obj) {
  if ($(obj).hasClass("layui-btn-disabled")) return;
  $(obj).removeClass("btn-primary").addClass("layui-btn-disabled").text("不可选择");

}
/*查看示例图片弹出层*/
function cksl() {
  layer.photos({
    photos: {
      "title": "", //相册标题
      "id": 123, //相册id
      "start": 0, //初始显示的图片序号，默认0
      "data": [   //相册包含的图片，数组格式
        {
          "alt": "图片名",
          "pid": 666, //图片id
          "src": "../assets/images/ckxlimg.jpg", //原图地址
          "thumb": "" //缩略图地址
        }
      ]
    }
    , anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
  });
}

$("input[name='wx-file']").on("change", function (e) {
  var that = this;
  var file = e.target.files[0] || e.dataTransfer.files[0];
  if (file) {
    var reader = new FileReader();
    reader.onload = function () {
      $(that).parents(".addbtn").addClass("hide").prev(".b-img").removeClass("hide");
      $(".wx-img").attr("src", this.result);
    }

    reader.readAsDataURL(file);
  }
})
$(document).on("click", ".wx-img_close", function () {
  $(this).parents(".b-img").addClass("hide").next(".addbtn").removeClass("hide");
})
// 打开新增菜单
function addzzPro() {
  layer.open({
    title: '新增菜单',
    skin: 'zp-popup',
    type: 1,
    area: '540px',
    content: $('#addzzPopup'),
    cancel: function () {
      setTimeout(function () {
        $("#addzzPopup").hide();
      }, 10);
    }
  });
}

$(".set_share").on("click", function () {
  $("#share_config").show();
  $("#share_config").siblings('.configurator').hide();
});

$(".phone_hd .title_text").on('click', function () {
  $(this).hide();
  $(".phone_hd .title_input").show().focus();

});

$(".phone_hd .title_input").on('blur', function () {
  $(this).hide();
  $(".phone_hd .title_text").show();
  if ($(this).val() == "") {
    $(".phone_hd .title_text").text($(".phone_hd .title_text").text());
  } else {
    $(".phone_hd .title_text").text($(this).val())
  }
  $(this).val("");
});
